package edu.ccut.saturn.basevalidate.prvalidate;

import edu.ccut.saturn.component.DefaultSaturnValidate;
import edu.ccut.saturn.component.ValidateResult;

public class IsPortNumberValidate extends DefaultSaturnValidate {

//	private static final String portRegExpr = "[0-9]+";

	private static final String integerRegExpr = "^[1-9]\\d*|0$";    //非负整数
	
	public void doValidate(Object value, Object[] args, ValidateResult result) {
			if (isValueValidate(value)) {
				sendError(_ERROR_, value, result);
			}
		}

	private Boolean isValueValidate(Object value) {
		
		if(!(value.toString()).matches(integerRegExpr)) {
			return true;
		}
		
		if (Double.parseDouble(value.toString()) > 65535) {
			return true;
		}
		
		return false;
	}
}
